package com.lanling.eduservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lanling.eduservice.entity.EduComment;
import com.lanling.eduservice.orther.R;
import com.lanling.eduservice.service.EduCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author 胡振华
 * @since 2021-03-04
 */
@RestController
@RequestMapping("/eduservice/edu-comment")
@CrossOrigin
public class EduCommentController {

    @Autowired
    private EduCommentService eduCommentService;

    @GetMapping("getCourseComments/{courseid}/{current}/{size}")
    public R getCourseComments(@PathVariable String courseid, @PathVariable long current, @PathVariable long size){
        Page<EduComment> eduCommentPage = new Page<>(current,size);
        Map<String, Object> map = eduCommentService.getCoursePageList(eduCommentPage,courseid);
        return R.ok().data(map);
    }

    //添加课程评论
    @PostMapping("addComment")
    public R addComment(@RequestBody(required = false) EduComment eduComment){
        boolean flag = eduCommentService.addComment(eduComment);
        if (flag){
            return R.ok();
        }else {
            return R.error();
        }
    }

}

